
//#include "head.h"
//#include <stdio.h>
#include <signal.h>

#include <iostream>

#include <workflow/WFFacilities.h>
#include <workflow/WFTaskFactory.h>
using std::cout;
using std::endl;


//初始化计数器的值为1
static WFFacilities::WaitGroup waitGroup(1);

void sighandler(int num)
{
    printf(">> sig num %d is comming\n", num);
    //调用一次done方法，计数器的值减1
    waitGroup.done();
}

void add(int a, int b, int & res)
{
    res = a + b;
}

void test0()
{
    signal(SIGINT, sighandler);

    int a = 1, b = 1, res;

    //goTask任务的用法就相当于将函数作为一个任务交给Workflow线程池来执行
    auto goTask = WFTaskFactory::create_go_task("test", add, a, b, std::ref(res));
    goTask->set_callback([&](WFGoTask *){
        printf("%d + %d = %d\n", a, b, res);
        waitGroup.done();
    });

    goTask->start();

    //当调用wait方法会阻塞当前线程
    waitGroup.wait();

    cout << "test0 exit" << endl;
}


int main()
{
    test0();
    return 0;
}

